/**
 * 详情对话框
 */
var OutOrderInfoDlg = {
    data: {
        outOrderStatus: "",
        outOrderNumber: "",
        outCustomerId: "",
        outCustomerName: "",
        settlementUnit: "",
        customerNumber: "",
        saleDeliveryCompany: "",
        outTime: "",
        transportWay:"",
        outWay: "",
        outStorehouseId:"",
        storehouseName: "",
        settlementWay: "",
        carNumber: "",
        setUnitId: "",
        setUnit: "",
        setLocation: "",
        setPeople: "",
        setTel: "",
        setMentiontime: "",
        getUnitId: "",
        getUnit: "",
        getLocation: "",
        getPeople: "",
        getTel: "",
        getMentiontime: "",
        salesman: "",
        salesmanTel: "",
        version: "",
        deptId: "",
        deliverId: "",
        note: "",
        returnNote: "",
        createUser: "",
        createTime: "",
        updateUser: "",
        updateTime: "",
        submitter: "",
        revokeMan: "",
        revokeTime: "",
        submitTime: ""
    }
};

/**
 * 添加或者修改页面
 * 货运订单表
 */
var OrderTransportInfoDlg = {
    data: {
        setUnitId: "",
        setUnit: "",
        setLocation: "",
        setLocationId: "",
        setPeople: "",
        setTel: "",
        setMentiontime: "",
        setWarehousepeople: "",
        setWarehousetel: "",
        setAddress: "",
        getUnitId: "",
        getUnit: "",
        getLocation: "",
        getLocationId: "",
        getPeople: "",
        getTel: "",
        getMentiontime: "",
        getWarehousepeople: "",
        getWarehousetel: "",
        getAddress: "",
    }
};

/**
 * 添加或者修改页面
 * 往来地址表
 */
var AddressInfoDlg = {
    data: {
        setLocation: "",
        setLocationId: "",
        setPeople: "",
        setTel: "",
    }
};

var submit = 0
layui.use(['form', 'admin', 'ax','laydate'], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var form = layui.form;
    var admin = layui.admin;
    var laydate = layui.laydate;
    //让当前iframe弹层高度适应
    admin.iframeAuto();

    //渲染时间
    laydate.render({
        elem: '#outTime' //出库时间
        	,value:new Date()
    });

    //执行一个laydate实例
    laydate.render({
        elem: '#setMentiontime' //提货时间
        	,value:new Date()
    });

    //执行一个laydate实例
    laydate.render({
        elem: '#getMentiontime' //到达时间
    });

    //获取详情信息，填充表单
    var ajax = new $ax(Feng.ctxPath + "/outOrder/detail?id=" + Feng.getUrlParam("id"));
    var result = ajax.start();
    form.val('outOrderForm', result.data);

    //表单提交事件
    form.on('submit(btnSubmit)', function (data) {
        var ajax = new $ax(Feng.ctxPath + "/outOrder/editItem", function (data) {
        	if (data.success) {
                Feng.success("Update successful!");
                window.location.href = Feng.ctxPath + '/outOrder'
			} else {
	            Feng.error("Update failed!" + data.message);
	            window.location.href = Feng.ctxPath + '/outOrder'
			}
        }, function (data) {
            Feng.error("Update failed!" + data.responseJSON.message)
        });
        ajax.set(data.field);
        ajax.start();

        return false;
    });

    //点击装货单位
    $("#setUnit").click(function(){
		submit = 0
        layer.open({
            type: 2,
            title: 'Select Loading Unit',
            area: ['900px', '600px'],
            content: Feng.ctxPath + '/orderTransport/toChoiceUnit?putgoodsCustomerId='+$("#outCustomerId").val(),
            end: function () {
            	if(submit == 1){
	                $("#setUnitId").val(OrderTransportInfoDlg.data.setUnitId);//装货单位id
	                $("#setUnit").val(OrderTransportInfoDlg.data.setUnit);//装货单位
	                $("#setLocation").val(OrderTransportInfoDlg.data.setLocation);
	                $("#setLocationId").val(OrderTransportInfoDlg.data.setLocationId);
	                $("#setPeople").val(OrderTransportInfoDlg.data.setPeople);
	                $("#setTel").val(OrderTransportInfoDlg.data.setTel);
            	}
            }
        });
    });

    //点击卸货单位
    $("#getUnit").click(function(){
		submit = 0
        layer.open({
            type: 2,
            title: 'Select Unloading Unit',
            area: ['900px', '600px'],
            content: Feng.ctxPath + '/orderTransport/toChoiceUnit?putgoodsCustomerId='+$("#outCustomerId").val(),
            end: function () {
            	if(submit == 1){
	                $("#getUnitId").val(OrderTransportInfoDlg.data.setUnitId);//卸货单位id
	                $("#getUnit").val(OrderTransportInfoDlg.data.setUnit);//卸货单位
	                $("#getLocation").val(OrderTransportInfoDlg.data.setLocation);
	                $("#getLocationId").val(OrderTransportInfoDlg.data.setLocationId);
	                $("#getPeople").val(OrderTransportInfoDlg.data.setPeople);
	                $("#getTel").val(OrderTransportInfoDlg.data.setTel);
            	}
            }
        });
    });

    //点击 装货地址
    $("#setLocation").click(function(){
        var setUnit = $("#setUnit").val();
        if (setUnit==null||setUnit=='') {
            layer.msg('Please select loading unit');
        } else {
			submit = 0
            layer.open({
                    type: 2,
                    title: 'Select Loading Address',
                    area: ['900px', '600px'],
                    content: Feng.ctxPath + '/orderTransport/toAddress?putgoodsId=' + $("#setUnitId").val(),
                end: function () {
            		if(submit == 1){
	                    $("#setLocation").val(AddressInfoDlg.data.setLocation);
	                    $("#setLocationId").val(AddressInfoDlg.data.setLocationId);
	                    $("#setPeople").val(AddressInfoDlg.data.setPeople);
	                    $("#setTel").val(AddressInfoDlg.data.setTel);
					}
                }
            });
        }
    });

    //点击 卸货地址
    $("#getLocation").click(function(){
        var getUnit = $("#getUnit").val();
        if (getUnit==null||getUnit=='') {
            layer.msg('Please select unloading unit');
        } else {
			submit = 0
            layer.open({
                    type: 2,
                    title: 'Select Unloading Address',
                    area: ['900px', '600px'],
                    content: Feng.ctxPath + '/orderTransport/toAddress?putgoodsId=' + $("#getUnitId").val(),
                end: function () {
            		if(submit == 1){
	                    $("#getLocation").val(AddressInfoDlg.data.setLocation);
	                    $("#getLocationId").val(AddressInfoDlg.data.setLocationId);
	                    $("#getPeople").val(AddressInfoDlg.data.setPeople);
	                    $("#getTel").val(AddressInfoDlg.data.setTel);
					}
                }
            });
        }
    });

    //点击 选择位置
    $("#choicep").click(function(){
        var getLocation = $("#getLocation").val();
        if (getLocation==null||getLocation=='') {
            layer.msg('Please select unloading address');
        } else {
			submit = 0
            layer.open({
                    type: 2,
                    title: 'Edit Unloading Address',
                    area: ['1000px', '800px'],
                    content: Feng.ctxPath + '/outOrder/editAddress?id=' + $("#getLocationId").val()+"&setLocationId="+$("#setLocationId").val(),
                end: function () {
            		if(submit == 1){
	                    $("#getLocation").val(AddressInfoDlg.data.setLocation);
					}
                }
            });
        }
    });

    //返回按钮
    $("#backupPage").click(function () {
        window.location.href = Feng.ctxPath + '/outOrder'
    });

});